home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-28 | 7.5 KB | 355 lines | [TEXT/MMCC] |
- // CMainWindow.cp -- window methods
- // Created 01/01/95 12:01 PM by AppMaker
-
- #include "CMainWindow.h"
- #include "PhoneControl_OOFILE.h"
-
- #include <UReanimator.h>
- #include <LStream.h>
- #include <LListBox.h>
- #include <LStdControl.h>
- #include <LTabGroup.h>
- #include <LEditField.h>
- #include <LString.h>
- #include <UDesktop.h>
- #include <PP_KeyCodes.h>
- #include <PP_Messages.h>
- #include "LStrTableView.h"
- #include <LTableMonoGeometry.h>
- #include <LTableMultiSelector.h>
-
- #include "stSetCursor.h"
-
- #define PPob_MainWindowID 200
- #define RidL_MainWindowID 200
-
-
-
- //----------
- // This is the function you register with URegistrar to create a
- // CMainWindow from a resource
-
- CMainWindow*
- CMainWindow::CreateMainWindowStream(
- LStream *inStream)
- {
- return (new CMainWindow(inStream));
- }
-
- //----------
- CMainWindow::CMainWindow()
- {
- }
-
- //----------
- CMainWindow::CMainWindow(
- LStream *inStream)
- : LWindow(inStream)
- {
- }
-
- //----------
- CMainWindow::~CMainWindow()
- {
- }
-
- //----------
- // This member function gets called once the containment hierarchy that contains
- // this pane has been built. It gives us a chance to get data members for
- // interesting subviews, and to do other operations now that our subviews exist.
- void
- CMainWindow::FinishCreateSelf()
- {
- mMainList = (LStrTableView *)FindPaneByID('Main');
- mFindButton = (LStdButton *)FindPaneByID('Fine');
- mFindField = (LControlEnablingEditField *)FindPaneByID('Edit');
- mLastNameButton = (LStdButton *)FindPaneByID('Lase');
- mFirstNameButton = (LStdButton *)FindPaneByID('Fire');
- mExtnButton = (LStdButton *)FindPaneByID('Extn');
- mPagerButton = (LStdButton *)FindPaneByID('Pagr');
- mDepartmentButton = (LStdButton *)FindPaneByID('Dept');
- mTitleButton = (LStdButton *)FindPaneByID('Tite');
- mShowAllButton = (LStdButton *)FindPaneByID('Shol');
-
- LTabGroup *tabGroup = new LTabGroup(this);
- mFindField->SetSuperCommander(tabGroup); // becomes the active field
-
- UReanimator::LinkListenerToControls(this, this, RidL_MainWindowID);
- // the purpose is to "connect" self to whatever controls
- // that we want to "listen" to
-
- mMainList->AddListener(this); // LStrTableView can't be included in RidL
-
- // any additional initialization for your window:
- mFindButton->Disable();
- mShowAllButton->Disable();
- mFindField->enablesControl(mFindButton);
- mCurrentSortButton = mLastNameButton;
- new LDefaultOutline(mFindButton);
- mMainList->SetTableGeometry(new LTableMonoGeometry(mMainList, 104 /* width */, 11));
- mMainList->SetTableSelector(new LTableMultiSelector(mMainList));
- }
-
-
- //----------
- void
- CMainWindow::DoFind()
- {
- // bit of a hack, if length is zero, select all records
- // that lets us call this routine after changing sort order
- // so we preserve the effect of the sort
- stSetCursor showWatch;
-
- Str255 fieldContents;
- mFindField->GetDescriptor(fieldContents);
- if (fieldContents[0]=='\0')
- mPhoneControl->selectAll();
- else {
- p2cstr(fieldContents);
- // 96/03/27 realised don't need to sort as always searching on indexed field
- mPhoneControl->unSorted();
- mPhoneControl->search(mCurrentSortField->startsWith((char*)fieldContents));
- }
- mFindField->SelectAll(); // so overtyping will clear
- RefreshBrowser();
- mShowAllButton->Enable();
- }
-
- //----------
- void
- CMainWindow::DoByLastName()
- {
- ChangeSortTo(mLastNameButton, mPhoneControl->LastName);
- }
-
- //----------
- void
- CMainWindow::DoByFirstName()
- {
- ChangeSortTo(mFirstNameButton, mPhoneControl->FirstName);
- }
-
- //----------
- void
- CMainWindow::DoByExtn()
- {
- ChangeSortTo(mExtnButton, mPhoneControl->Extn);
- }
-
- //----------
- void
- CMainWindow::DoByPager()
- {
- ChangeSortTo(mPagerButton, mPhoneControl->Pager);
- }
-
- //----------
- void
- CMainWindow::DoByDepartment()
- {
- ChangeSortTo(mDepartmentButton, mPhoneControl->Department);
- }
-
- //----------
- void
- CMainWindow::DoByTitle()
- {
- ChangeSortTo(mTitleButton, mPhoneControl->Title);
- }
-
- void
- CMainWindow::ChangeSortTo(LStdButton* newSortBtn, dbChar& sortField)
- {
- Str255 newSortTitle;
- mCurrentSortButton = newSortBtn;
- newSortBtn->GetDescriptor(newSortTitle);
- LStr255 newTitle(newSortTitle);
- newTitle.Insert("Find ", 5, 0);
- mFindButton->SetDescriptor(newTitle);
-
- mCurrentSortField = &sortField;
- DoShowAll();
- }
-
- //----------
- void
- CMainWindow::DoShowAll()
- {
- // only enabled if restricted the list
-
- stSetCursor showWatch; // just a watch cursor
-
- // 93/06/27 in case we just did a Find, which removed a sort order
- mPhoneControl->setSortOrder(*mCurrentSortField);
-
- mPhoneControl->selectAll();
- RefreshBrowser();
- mShowAllButton->Disable();
- }
-
-
- //----------
- void
- CMainWindow::ListenToMessage(
- MessageT inMessage,
- void *ioParam)
- {
- switch (inMessage) {
- case 'Find':
- DoFind();
- break;
-
- case 'ByLe':
- DoByLastName();
- break;
-
- case 'ByFe':
- DoByFirstName();
- break;
-
- case 'ByEn':
- DoByExtn();
- break;
-
- case 'ByPr':
- DoByPager();
- break;
-
- case 'ByDt':
- DoByDepartment();
- break;
-
- case 'ByTe':
- DoByTitle();
- break;
-
- case 'Shol':
- DoShowAll();
- break;
-
- default:
- if (!OOFILEhandlesMessage(inMessage, ioParam))
- ; // do something
- break;
- }
- }
-
- //----------
- Boolean
- CMainWindow::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- // +++ Add cases here for the commands you handle
- // Remember to add same cases to FindCommandStatus below
- // to enable/disable the commands
- default:
- cmdHandled = OOFILEhandlesMessage(inCommand, ioParam);
- if (!cmdHandled)
- cmdHandled = LWindow::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- //----------
- void
- CMainWindow::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- outUsesMark = false;
-
- switch (inCommand) {
-
- // +++ Add cases here for the commands you handle
- default:
- LWindow::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-
- //----------
- Boolean
- CMainWindow::FocusDraw()
- {
- Boolean focused = LView::FocusDraw();
-
- if (focused) {
- AuxWinHandle awHndl;
- CTabHandle awCTable;
- ColorSpec contentSpec;
-
- GetAuxWin(GetMacPort(), &awHndl);
- awCTable = (**awHndl).awCTable;
- contentSpec = (**awCTable).ctTable [wContentColor]; // should search vs. index
- ::RGBBackColor(&contentSpec.rgb);
- }
-
- return focused;
- }
-
-
- void CMainWindow::SetDatabase(CdbPhoneControl* inPhoneControl)
- {
- // our copy of the database, if we need to change its state in our Do methods
- mPhoneControl = inPhoneControl;
-
- // link view to controls created in FinishCreateSelf
- dbView* theView = new dbView(inPhoneControl);
- *theView << inPhoneControl->LastName << inPhoneControl->FirstName << inPhoneControl->Title << inPhoneControl->Extn << inPhoneControl->Department << inPhoneControl->Pager ;
- AdoptView(theView);
- BrowseViewWithTable(mMainList);
- inPhoneControl->setSortOrder(inPhoneControl->LastName);
- mCurrentSortField = &(mPhoneControl->LastName);
- }
-
-
- Boolean
- CMainWindow::HandleKeyPress(
- const EventRecord &inKeyEvent)
- {
- Boolean keyHandled = false;
-
- switch (inKeyEvent.message & charCodeMask) {
-
- case char_Enter:
- case char_Return:
- mFindButton->SimulateHotSpotClick(kControlButtonPart);
- keyHandled = true;
- break;
-
- default:
- keyHandled = LWindow::HandleKeyPress(inKeyEvent);
- break;
- }
- return keyHandled;
- }
-
-
- // lightweight class to wrap creating CMainWindow
-
- LWindow* CMainWindowFactory::makeWindow(const bool loadData) const
- {
- stSetCursor showWatch;
-
- CdbPhoneControl* realTable = (CdbPhoneControl*) mTable; // safe downcast
- // would later use dynamic_cast to test the above
- CMainWindow *win = (CMainWindow *)LWindow::CreateWindow(PPob_MainWindowID, mCommander);
- win->SetDatabase(realTable);
- if (loadData)
- win->LoadBrowseData();
- return (LWindow*) win;
- }
-
-
-